package graphic.mycomponents;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import core.ServerParameters;

import utility.GraphicUtilsFactory;

public class ToolBarDialogClassNavigationButton extends JButton {
	
	String dialogClassName;
	
	public ToolBarDialogClassNavigationButton(String imageName, String dialogClassName, String toolTipText, String altText)
	{
		super();
		
		this.dialogClassName = dialogClassName;
		
		URL imageURL = GraphicUtilsFactory.class.getClassLoader().getResource(ServerParameters.BUTTON_IMAGE_PATH + imageName);
		
		super.setToolTipText(toolTipText);
		super.setIcon(new ImageIcon(imageURL, altText));		
		super.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				try {
					try {
						Class.forName(ToolBarDialogClassNavigationButton.this.dialogClassName).newInstance();
					} catch (InstantiationException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					//new NewUserDialog();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}					
			}
		});
	}	
}
